
component accessors="true" output="false" extends="AbsDelegate"
{

	property name="RoleFactory" type="it.millemultimedia.easyBlog.factory.RoleFactory";

	public it.millemultimedia.easyBlog.delegate.RoleDelegate function init( required Any dataObject ){
		
		variables.dataObject = arguments.dataObject;
		
		return this;
	}
	
	public it.millemultimedia.easyBlog.validator.RoleValidator function getValidator(){
		
		return getRoleFactory().getValidator();
	}
	
	public it.millemultimedia.easyBlog.model.Role function createInstance(){
		
		return getRoleFactory().createInstance();
	}

	public void function create( required Any Role ){
		
		variables.dataObject.create( arguments.Role );
		
	}

	public void function update( required Any Role ){
		
		variables.dataObject.update( arguments.Role );
		
	}

	public it.millemultimedia.easyBlog.model.Role function read( required Any Role, Boolean lazy="true" ){
	
		var idRole = "";
		var Roles = variables.dataObject.read( arguments.Role );
		var permissions = queryNew( 'idPremission' );
		var preferences = queryNew( 'idPreference' );
		
		if( arguments.lazy eq false ){
		
			idRole = valueList( Roles.idRole );
			
			permissions = getPermissions( idRole );
			
			preferences = getPreferences( idRole );
		
		}
		
		Role = getRoleFactory().get( Roles, permissions, preferences );
		
		return Role;
		
	}

	public void function delete( required Any Role ){
		
		variables.dataObject.delete( arguments.Role );
		
	}

	public it.millemultimedia.easyBlog.model.Role[] function list( required Any Role, Boolean lazy="true", Numeric start=0, Numeric count=0 ){
	
		var list = "";
		var idRole = "";
		var Roles = variables.dataObject.list( arguments.Role );
		var permissions = queryNew( 'idPremission' );
		var preferences = queryNew( 'idPreference' );
		
		if( arguments.lazy eq false ){
		
			idRole = valueList( Roles.idRole );
			
			permissions = getPermissions( idRole );
			
			preferences = getPreferences( idRole );
		
		}
		
		list = getRoleFactory().list( Roles, permissions, preferences, arguments.start, arguments.count );
		
		return list;
		
	}

	private Query function getPermissions( required String idRole ){
		
		return variables.dataObject.getPermissions( arguments.idRole );
		
	}

	private Query function getPreferences( required String idRole ){
		
		return variables.dataObject.getPreferences( arguments.idRole );
		
	}

}


